package com.ny.demo;

import java.sql.*;
import java.util.Scanner;

public class Delete {
    private static final String URL = "jdbc:mysql://localhost:3306/usersdb";
    private static final String DB_USERNAME = "root";
    private static final String DB_PASSWORD = "123456";
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection(URL,DB_USERNAME,DB_PASSWORD);
        String sql = "delete from userdb where id =?";
        PreparedStatement ps = conn.prepareStatement(sql);
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入ID：");
        int id = scan.nextInt();
        ps.setInt(1,id);
        int i = ps.executeUpdate();
        if(i>0){
            System.out.println("删除成功！");
        }else{
            System.out.println("删除失败！");
        }
    }

}
